<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">  
    <head>  
        <title>项目管理</title>  
        <script src="/scripts/boot.js"></script>
        <style>
        	html,body{
			   margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
			}
			body{
				padding:20px;
			}
        </style>
    </head>  
    <body>
	<div class="title-list mb-20"><span class="title-listbg"></span><span>项目列表</span></div>
		<div id="queryForm"  class="mini-toolbar1" style="border-bottom:0;padding:0px;">
			<table style="width:100%;">
				<tr>
					<td style="width:100%;">
						<div class="mb-20 position-rel">
							<span class="search-title search-ml20">名称</span><input id = "name" name="name" class="mini-textbox search-200px" value="">
							<a class="add-botton search-ml60" onclick="list.search()">查询</a>
							<a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
						</div>
					</td>
				</tr>
			</table>
		</div>
   		<div class="mini-fit">
			<div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/item/listByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="id">
			    <div property="columns">
			        <div type="indexcolumn" width="30" headerAlign="center" align="center">编号</div>
			        <div field="name" width="300" headerAlign="center" align="center" allowSort="false">名称</div>
			        <div field="number" width="300" headerAlign="center" align="center" allowSort="false">编号</div>
			        <div field="id" width="300" headerAlign="center" align="center" allowSort="false">角色</div>
			        <div name="action" width="200" headerAlign="center" align="center" allowSort="false">操作</div>
			    </div>
			</div>   
		</div>
		<script type="text/javascript">
            var grid,roleIds;
            var list = {
                //页面初始化
                init: function() {
                    mini.parse();
                    grid = mini.get("datagrid1");
                    grid.load();
                    grid.on("drawcell", function (e) {
                        var column = e.column;
                        var record = e.record;
                        if(column.field=="id"){
                        	$.ajax({
                        		url:"/item/listRoles",
                        		type:"post",
                        		data:{"id":record.id},
                        		async:false,
                        		success:function(data){ 
                        			data = $.parseJSON(data);
                        			var roleName;
                        			$.each(data,function(i,k){ 
                        				if(i!=0){
                        					roleName += ","+k.roleName
                        				}else{
                        					roleName = k.roleName
                        				}
                        			})
                        			e.cellHtml = roleName;
                        		}
                        	})
                        }
                        if (column.name == "action") {
                            e.cellHtml = '<a class="revise-botton" href="javascript:list.add()">分配角色</a>';
                        }
                    });
                },
                //    新增或编辑
                add: function (opt) {
                    var row = grid.getSelected();
                	$.ajax({
                		url:"/item/listRoles",
                		data:{"id":row.id},
                		async:false,
                		success:function(data){
                			data = $.parseJSON(data);
                			$.each(data,function(i,k){ 
                				if(i!=0){
                					roleIds += ","+k.id
                				}else{
                					roleIds = k.id
                				}
                			})
                		}
                	});
                    mini.open({
                        url: "/rbac/item/add.html",
                        title: "分配角色",
                        width: 1000,
                        height: 360,
                        onload: function () {
                        	var row = grid.getSelected();
                            var data = {"id": row.id,"roleIds":roleIds};
                            var iframe = this.getIFrameEl();
                            iframe.contentWindow.view.SetData(data);
                        },
                        ondestroy: function (action) {
                            grid.reload();
                        }
                    });
                },
               
                // 查询
                search: function () {
                    var data = {
                        "name": mini.get("name").getValue(),
                    };
                    grid.load(data);
                },
                
                //重置
                reset:function(){
                    var form = new mini.Form("queryForm");
                    form.reset();
                    grid.load()
                }
              
            };
            list.init();
		</script> 
	</body>  
</html>  